<?php
App::uses('AppController', 'Controller');
/**
 * Nincludes Controller
 *
 * @property Ninclude $Ninclude
 * @property PaginatorComponent $Paginator
 */
class NincludesController extends AppController {

/**
 * Components
 *
 * @var array
 */
	var $components = array('RequestHandler','Paginator');
	public $helpers = array('Js');

/**
 * index method
 *
 * @return void
 */
	public function index() {
				$this->layout = __('template_admin');

		$this->Ninclude->recursive = 0;
		$this->set('nincludes', $this->Paginator->paginate());
	}

/**
 * view method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function view($id = null) {
		if (!$this->Ninclude->exists($id)) {
	$this->Session->setFlash(__('Invalid ninclude.'),'alert-danger alert-dismissable',array('class'=>'alert-danger alert-dismissable'));

		}
		$options = array('conditions' => array('Ninclude.' . $this->Ninclude->primaryKey => $id));
		$this->set('ninclude', $this->Ninclude->find('first', $options));
	}

/**
 * add method
 *
 * @return void
 */
	public function add() {
				$this->layout = __('template_admin');

		if ($this->request->is('post')) {
			$this->Ninclude->create();
			if ($this->Ninclude->save($this->request->data)) {
			$this->Session->setFlash(__('The Ninclude has been saved.'),'alert alert-success alert-dismissable',array('class'=>'alert alert-success alert-dismissable'));

				return $this->redirect(array('action' => 'index'));
			} else {
	$this->Session->setFlash(__('The Ninclude could not be saved. Please, try again.'),'alert-danger alert-dismissable',array('class'=>'alert-danger alert-dismissable'));

			}
		}
		$activities = $this->Ninclude->Activity->find('list');
		$this->set(compact('activities'));
	}

/**
 * edit method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function edit($id = null) {
				$this->layout = __('template_admin');

		if (!$this->Ninclude->exists($id)) {
	$this->Session->setFlash(__('Invalid ninclude.'),'alert-danger alert-dismissable',array('class'=>'alert-danger alert-dismissable'));
		}
		if ($this->request->is(array('post', 'put'))) {
			if ($this->Ninclude->save($this->request->data)) {
		$this->Session->setFlash(__('The Ninclude has been saved.'),'alert alert-success alert-dismissable',array('class'=>'alert alert-success alert-dismissable'));

				return $this->redirect(array('action' => 'index'));
			} else {
		$this->Session->setFlash(__('The Ninclude could not be saved. Please, try again.'),'alert-danger alert-dismissable',array('class'=>'alert-danger alert-dismissable'));

			}
		} else {
			$options = array('conditions' => array('Ninclude.' . $this->Ninclude->primaryKey => $id));
			$this->request->data = $this->Ninclude->find('first', $options);
		}
		$activities = $this->Ninclude->Activity->find('list');
		$this->set(compact('activities'));
	}

/**
 * delete method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function delete($id = null) {
		$this->layout = __('template_admin');
		$this->Ninclude->id = $id;
		if (!$this->Ninclude->exists()) {
	$this->Session->setFlash(__('Invalid ninclude.'),'alert-danger alert-dismissable',array('class'=>'alert-danger alert-dismissable'));
		}
		$this->request->onlyAllow('post', 'delete');
		if ($this->Ninclude->delete()) {
		$this->Session->setFlash(__('The Ninclude has been deleted.'),'alert alert-success alert-dismissable',array('class'=>'alert alert-success alert-dismissable'));

		} else {
		$this->Session->setFlash(__('The country could not be deleted. Please, try again.'),'alert-danger alert-dismissable',array('class'=>'alert-danger alert-dismissable'));

		}
		return $this->redirect(array('action' => 'index'));
	}


public  function searchByNinclude($ninclude=null) 
	{
       
	if($ninclude!=null or $ninclude!="")
		{	    
				$this->set('nincludes', $this->Paginator->paginate('Ninclude', array('Ninclude.label like' =>'%'.$ninclude.'%')));
		}else 
		    {	
				$this->set('nincludes', $this->Paginator->paginate());
			}

			
	}

}
